home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / ARGONET / PD / MATHS / RLAB / RLAB125.ZIP / !RLaB / rlib / input < prev    next >
Text File  |  1995-01-14  |  1KB  |  45 lines

  1. //-------------------------------------------------------------------//
  2.  
  3. //  Syntax:    input ( STRING )
  4. //        input ( STRING , "s" )
  5.  
  6. //  Description:
  7.  
  8. //  The input function provides an easy method for users to get a
  9. //  simple response from the keyboard. The STRING argument is printed
  10. //  on the standard output (usually the screen), and the program waits
  11. //  until input is entered. Input then returns the input, which can be
  12. //  either a string, or a number. If you want to force the input to be
  13. //  a string, then use the second, and optional argument, "s" to force
  14. //  the return value to be a string.
  15.  
  16. //  If the user does not enter anything when prompted, then input
  17. //  returns an empty matrix.
  18.  
  19. //-------------------------------------------------------------------//
  20.  
  21. input = function ( STRING, S )
  22. {
  23.   if (!exist (STRING)) { STRING = "input: "; }
  24.  
  25.   fprintf ("stdout", "%s", STRING);
  26.   ans = getline ("stdin");
  27.  
  28.   if (length (ans) == 0)
  29.   {
  30.     return [];
  31.   else
  32.     if (exist (S))
  33.     {
  34.       if (class (ans.[1]) == "num")
  35.       {
  36.         return num2str (ans.[1])
  37.       else
  38.         return ans.[1];
  39.       }
  40.     else
  41.       return ans.[1]
  42.     }
  43.   }
  44. };
  45.